define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function ($, undefined, Backend, Table, Form, undefined) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'yexam/combo_list/index' + location.search,
                    add_url: 'yexam/combo_list/add',
                    edit_url: 'yexam/combo_list/edit',
                    del_url: 'yexam/combo_list/del',
                    multi_url : "yexam/combo_list/multi",
                    //table: 'question_type',
                },
                pageList : [15,30,60,80,100]
            });

            var table = $("#question_type");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                escape: false,
                pk: 'id',
                sortName: 'sort',
                sortOrder:'asc',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'sort', title: "排序",operate: false},
                        {field: 'id', title: __('Id')},
                        {field: 'combo_name', title: __('套餐名称'),align: 'left',width:'100px',},
                        {field: 'category_name', title: __('套餐分类'),align: 'left',formatter:Table.api.formatter.search},
                        {field: 'category_id', title: __('分类id'),align: 'left',visible : false},
                        {field: 'combo_price', title: __('售价'),align: 'left',},
                        {field: 'combo_yprice', title: __('原价'),align: 'left',},
                        {field: 'combo_on', title: __('是否上架'),align: 'left',formatter: Table.api.formatter.toggle},
                        {field: 'is_module', title: __('模块显示'),align: 'left', formatter : Table.api.formatter.toggle},
                        {field: 'is_index', title: __('是否首页'),align: 'left', formatter : Table.api.formatter.toggle},
                        {field: 'is_share', title: __('是否分享'),align: 'left', formatter : Table.api.formatter.toggle},
                        {field: 'combo_tags', title: __('套餐标签'),align: 'left',width:'400px'},
                        {field: 'create_time', title: __('创建时间'),operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            formatter:{
            },
            bindevent: function () {
                $("#c-package_ids").data("params", function (obj) {
                    return {custom: {category_id: $("#c-category_id").val()}};
                });
                Form.api.bindevent($("form[role=form]"));
                // 是否上架
                $('input[type=radio].combo_on').change(function () {
                    if (Number($(this).val()))
                    {
                        $(this).parent().parent().siblings().show();
                    }
                    else
                    {
                        $(this).parent().parent().siblings().hide();
                    }
                });
                //=====  有效期
                $('input[type=radio].combo_time').change(function () {
                    if (Number($(this).val()) === 1) // 年限
                    {
                        $('.error-tip').html('');
                    }
                    else // 考季
                    {
                        if ($('#category option:selected').data('val') == '')
                        {
                            $('.error-tip').html('请填写分类考试时间');
                        }
                        else
                            $('.error-tip').html('');
                    }
                });
                //============ 选择分类
                $('#category').change(function () {
                    $('#category_name').val($('#category option:selected').data('str'));
                });
            },
        }
    };
    return Controller;
});
